library(tidyverse)

ggplot(mpg) +
  geom_point(aes(x = displ, y = hwy))

ggplot(mpg) +
  geom_point(aes(x = cyl, y = hwy))

ggplot(mpg) +
  geom_point(aes(x = displ, y = hwy, color = class))

ggplot(mpg) +
  geom_point(aes(x = displ, y = hwy)) +
  facet_wrap(~ class, nrow = 2)

ggplot(mpg) +
  geom_point(aes(x = displ, y = hwy)) +
  facet_grid(drv ~ cyl)

ggplot(mpg) +
  geom_point(aes(x = displ, y = hwy, color = drv)) +
  geom_smooth(aes(x = displ, y = hwy, 
                  color = drv, linetype = drv))

ggplot(mpg, aes(x = displ, y = hwy, color = drv)) +
  geom_point() +
  geom_smooth(aes(linetype = drv))

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point(aes(color = class)) +
  geom_smooth(show.legend = F)

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point(aes(color = class)) +
  geom_smooth(data = filter(mpg, class == "subcompact"),
              se = FALSE)


demo <- tribble(
  ~a,     ~b,
  "bar1", 20,
  "bar2", 30,
  "bar3", 40
)
ggplot(demo) +
  geom_bar(aes(x = a, y = b), stat = "identity")

ggplot(diamonds) +
  geom_bar(aes(x = cut))

ggplot(diamonds) +
  geom_bar(aes(x = cut, y = ..prop..))

ggplot(diamonds) +
  geom_bar(aes(x = cut, y = ..prop.., group = 1))

bar <- ggplot(diamonds) +
  geom_bar(aes(x = cut, fill = cut),
           show.legend = F, width = 1) +
  theme(aspect.ratio = 1) +
  labs(x = NULL, y = NULL)

bar + coord_flip()
bar + coord_polar()

